#include "Player.hpp"

Player::Player(Map* m, std::string inName, SpriteSet* set, float x, float y, byte dir):PlayerEntity(m, x, y,dir), ServerEntity(){
    name = inName;
    characterSet = set;
    facingDir = Entity::dir_S;
	collisionBoxColor = sf::Color::Magenta;
}

void Player::draw(sf::RenderTarget& target, sf::RenderStates states) const{
    states.transform *= sf::Transformable::getTransform();
	
    if(moving){
        if(direction&Entity::dir_N)
            target.draw(*characterSet->sprites[0], states);
        else if(direction&Entity::dir_E)
            target.draw(*characterSet->sprites[1], states);
        else if(direction&Entity::dir_S)
            target.draw(*characterSet->sprites[2], states);
        else if(direction&Entity::dir_W)
            target.draw(*characterSet->sprites[3], states);
    }else{
        if(facingDir&Entity::dir_N)
            target.draw(*characterSet->sprites[4], states);
        else if(facingDir&Entity::dir_E)
            target.draw(*characterSet->sprites[5], states);
        else if(facingDir&Entity::dir_S)
            target.draw(*characterSet->sprites[6], states);
        else if(facingDir&Entity::dir_W)
            target.draw(*characterSet->sprites[7], states);
    }
	sf::RectangleShape collisionBox;
	collisionBox.setOutlineThickness(1.0);
	collisionBox.setFillColor(sf::Color::Transparent);
	collisionBox.setOutlineColor(collisionBoxColor);
	collisionBox.setSize(sf::Vector2f(cWidth, cHeight));
    states.transform = states.transform.translate(cxOffset, cyOffset);
	target.draw(collisionBox, states);
}

void Player::move(){
    PlayerEntity::move();
}

void Player::setMove(byte dir){
    if(dir)
        facingDir = dir;

    Entity::setMove(dir);
}

void Player::bind(lua_State* luaState){

}

void Player::push(lua_State* luaState){
    
}